#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
class Solution {
public:
    string compressString(string S) {
        string retStr;
        int count = 0;
        char ch = S[0];
        for (auto e : S)
        {
            if (e == ch)
            {
                ++count;
            }
            else
            {
                retStr.push_back(ch);
                retStr += to_string(count);
                count = 1;
                ch = e;
            }
        }
        if (ch != '/0')
        {
            retStr += ch + to_string(count);
        }
        if (retStr.size() < S.size())
            return retStr;
        return S;
    }
};
int main()
{
    string retStr;
    retStr = Solution().compressString("aabcccccaaa");
    for (auto e : retStr)
    {
        cout << e;
    }
    cout << endl;
    return 0;
}